package nn;

import java.util.ArrayList;

import nn.networks.CPNetwork;
import nn.networks.KohonenNetwork;
import nn.phraseparameters.CPPhraseParameters;

public class CPNetworkTest {
	public static void main(String[] args) throws Exception {
		boolean test = false;
		System.out.println("start");
		boolean printNetwork = true;

		CPNetwork net = new CPNetwork();
		String path;
		path = "configurations/CP_KOH";
		net.readConfFile2(path);
		// net.layerList.get(1).setNeighborhoodSize(-1);

		float[] result;
		ArrayList<float[]> inputsList = new ArrayList<>();
		ArrayList<float[]> outputsList = new ArrayList<>();
		int ii = 0;
		for (int x = 0; x < 2; ++x) {
			for (int y = 0; y < 2; ++y) {
				for (int z = 0; z < 2; ++z) {
					if (test)
						if (x == y && y == z) {
							continue;
						}
					float[] input = { x, y, z };
					float[] output = new float[1];
					inputsList.add(input);
					if ((x + y + z) % 2 == 0) {
						output[0] = (float) 0;
					} else {
						output[0] = (float) 1;
					}
					outputsList.add(output);
				}
			}
		}
		ArrayList<CPPhraseParameters> phraseParList = new ArrayList<>();
		float grosStart = (float) 0.1;// 0.000025;
		float kohStart = (float) 0.7;// 0.000025;
		phraseParList.add(new CPPhraseParameters(8000, 1, kohStart, grosStart));
		phraseParList.add(new CPPhraseParameters(16000, -1, kohStart / 2, grosStart / 2));
		phraseParList.add(new CPPhraseParameters(24000, -2, kohStart / 4, grosStart / 4));
		phraseParList.add(new CPPhraseParameters(32000, 0, kohStart / 8, grosStart / 8));

		// Learning
		net.epochLearn(phraseParList, inputsList, outputsList);

		// printing result
		System.out.println();
		if (test) {
			inputsList = new ArrayList<>();
			float[] input1 = { 0, 0, 0 };
			float[] input2 = { 1, 1, 1 };
			inputsList.add(input1);
			inputsList.add(input2);
		}
		for (float[] it : inputsList) {
			result = net.calculate(it);
			System.out.printf("%d %d %d -> %f%n", (int) it[0], (int) it[1], (int) it[2], result[0]);
		}
	}
}
